package com.example.zhangxin.zyfypt_124zx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.zhangxin.zyfypt_124zx.R;
import com.example.zhangxin.zyfypt_124zx.iface.RegisterListener;
import com.example.zhangxin.zyfypt_124zx.model.RegisterModel;

import static com.example.zhangxin.zyfypt_124zx.R.id.editText2;

public class RegisterActivity extends AppCompatActivity {

    private TextView tv,tv1,tv2,tv3,tv4,tv5,tv6;
    private EditText et2,et3,et4,et5,et6;
    private Button bt1,bt2,bt3;
    private ImageView iv;
    private String username="",password="",password2="",tel="",realname="",sessionID="";//用户名密码

    RegisterListener registerListener=new RegisterListener() {
        @Override
        public void onResponse(String beanList) {

            //String.valueOf(1)  beanList!= String.valueOf(1)
            if(beanList.equals("1")){
                Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
            }else{

                Toast.makeText(RegisterActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
            }

        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        tv = (TextView) findViewById(R.id.textView);
        tv1 = (TextView) findViewById(R.id.textView1);
        tv2 = (TextView) findViewById(R.id.textView2);
        tv3 = (TextView) findViewById(R.id.textView3);
        tv4= (TextView) findViewById(R.id.textView4);
        tv5= (TextView) findViewById(R.id.textView5);
        tv6= (TextView) findViewById(R.id.textView6);
        et2 = (EditText) findViewById(editText2);
        et3 = (EditText) findViewById(R.id.editText3);
        et4 = (EditText) findViewById(R.id.editText4);
        et5 = (EditText) findViewById(R.id.editText5);
        et6 = (EditText) findViewById(R.id.editText6);
        bt1 = (Button) findViewById(R.id.button1);
        bt2= (Button) findViewById(R.id.button2);
        bt3 = (Button) findViewById(R.id.button3);
        iv =(ImageView)findViewById(R.id.imageView);



        bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取注册信息，确定 非空，比对密码一致
                //调model，在listener中判断返回

                username=et2.getText().toString();
                password=et3.getText().toString();
                password2=et4.getText().toString();
                realname=et5.getText().toString();
                tel=et6.getText().toString();
                if(password.equals(password2))
                {
                    RegisterModel model=new RegisterModel();
                    model.getResultList(username,password,tel,registerListener);

                }

            }
        });

        bt3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
                startActivity(intent);
            }
        });
    }

}
